<template>
  <div class="page-container">
    <!-- 固定头部 -->
    <header class="header">
      <div class="header-content">
        <!-- 左侧logo -->
        <div class="logo" @click="toIndex()">
          <img
            class="image_top"
            referrerpolicy="no-referrer"
            src="./assets/img/top.png"
          />
        </div>

        <!-- 右侧按钮 -->
        <div class="header-actions">
          <el-button class="login_btn1 my_btn" @click="toAccount" v-if="name != null && name != ''">My Account</el-button>
          <el-button class="login_btn my_btn" @click="tologin" v-if="name == null || name == ''">Login</el-button>
          <el-button class="postads_btn" @click="postAds">Post&nbsp;Ads</el-button>
        </div>
      </div>
    </header>

    <!-- 可滚动内容区域 -->
    <main class="main-content">
      <div class="content">
        <!--   查询条件   -->
        <div class="box_1 flex-row">
          <el-select v-model="categoryName" class="search1" placeholder="Please Select">
            <el-option v-for="category in categorys" :label="category.name" :value="category.id" :key="category.id" />
          </el-select>
          <!--        <el-input class="search1" v-model="city" placeholder="City name"></el-input>-->
          <el-select
            class="search1"
            v-model="cityName"
            filterable
            remote
            reserve-keyword
            placeholder="City name"
            :remote-method="remoteMethod"
            :loading="loading">
            <el-option
              v-for="item in cityOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
          <el-input class="search1" v-model="queryName" placeholder="Enter query"></el-input>

          <el-button class="search2" style="margin-left: auto;margin-right: 5px;" @click="toSearch">Search</el-button>
        </div>

        <div class="box_2 flex-row">
          <img
            class="thumbnail_2"
            referrerpolicy="no-referrer"
            src="./assets/img/home.png"
          />
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">Home</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/cmsIndex2?zhou=' + form.location }">
              {{ form.location }}
            </el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/cmsIndex3?zhou='+ form.location + '&city=' + form.city }">
              {{ form.city }}
            </el-breadcrumb-item>
            <el-breadcrumb-item>
              {{ form.type }}
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>

        <!-- 这里放置你的页面主要内容 -->
        <div class="center_content">
          <!-- 标题 -->
          <div class="title2">
            {{form.title}}
          </div>

          <!-- 发布时间和查看次数 -->
          <div class="time2">
              <span>
                <img style="width: 12px; height: 12px;" src="./assets/img/time.png">
              </span>
            <span>
                Update&nbsp;time：{{ createTime }}
              </span>
            <span>
                <img style="width: 16px; height: 12px;" src="./assets/img/view.png">
              </span>
            <span>
                View: {{ form.views }}
              </span>
          </div>

          <!-- 轮播图 -->
          <div class="banner2" v-if="fileListPut.length > 0">
            <div class="photo-list">
              <div
                v-for="(photo, index) in fileListPut"
                :key="index"
                class="photo-item"
              >
                <img :src="photo.url" class="thumbnail">
              </div>
            </div>
          </div>

          <div class="split2">
            Related Introduction
          </div>

          <div>
            <div class="left" style="padding: 10px 20px;">
              <br>
                <div class="ql-editor" v-html="form.description"></div>
              <br>
            </div>
          </div>

          <!-- 表格 -->
          <div class="container2">
            <table style="width: 90%" bgcolor="#FAEBF1">
              <tr>
                <td>Post ID:</td>
                <td>{{ form.id }}</td>
              </tr>
              <tr>
                <td>Poster's age:</td>
                <td>{{ form.age }}</td>
              </tr>
              <tr>
                <td>Mobile:</td>
                <td>{{ form.phone }}</td>
              </tr>
              <tr>
                <td>City:</td>
                <td>{{ form.city }}</td>
              </tr>
              <tr>
                <td>Address:</td>
                <td>{{ form.fullAddress }}</td>
              </tr>
            </table>
          </div>

        </div>
      </div>
    </main>

    <!-- 固定底部 -->
    <footer class="footer">
      <div class="footer1">Terms｜About&nbsp;us｜Contact&nbsp;us｜Privacy</div>
      <div class="footer1">Email:topgirlspage88@gmail.com</div>
      <hr>
      <div class="footer1">Copyright&nbsp;©&nbsp;2025&nbsp;topgirlspage.com&nbsp;All&nbsp;Rights&nbsp;Reserved</div>
    </footer>

    <!--  弹窗提示  -->
    <el-dialog title="Publisth ad rules" :visible.sync="outerVisible">
      Before the topgirlspage.com writes the advertisement
      You agree to follow these rules:
      <br>
      1.All posters must be of legal age.
      <br>
      2.You may not post any content or information of anyone that is not of legal age.
      <br>
      3.You may not mention or infer that any person advertised is of less than legal age. Words like "young", "school girl-like" or similar may not be used.
      <br>
      4.You may not post images or personal information of another person without consent.
      <br>
      5.It is forbidden to publish any pictures and words involving nudity, genitalia, violence, drugs, guns, child trafficking and women. Once found, the account will be deleted and IP login will be permanently closed
      <div slot="footer" class="dialog-footer">
        <el-button @click="outerVisible = false">Cancle</el-button>
        <el-button type="primary" @click="toPublish">I Agree</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getCityAndZhou } from "@/api/cms/city";
import { getById } from "@/api/cms/ad";

// 引入富文本编辑器样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import {mapGetters} from "vuex";


export default {
  data() {
    return {
      createTime: '',
      // 发布弹出框
      outerVisible: false,
      // 城市筛选
      list: [],
      cityOptions: [],
      loading: false,
      // 顶部查询条件
      categoryName:'',
      cityName: '',
      queryName: '',

      // 表单内容
      form: {
        views: 0
      },
      // 图片列表
      fileListPut: [],
      // 视频链接
      videoUrl: '',

      categorys: [{
        id: 2,
        name: 'Bodyrubs'
      },{
        id: 3,
        name: 'Escorts'
      },{
        id: 4,
        name: 'All'
      }],
      url2: process.env.VUE_APP_BASE_API,
    }
  },
  methods: {
    getCityAndZhou() {
      getCityAndZhou().then(res => {
        this.list = res.data.map(item => {
          return { value: `${item.zhouName}`, label: `${item.zhouName}` };
        })
      });
    },
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.cityOptions = this.list.filter(item => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        }, 200);
      } else {
        this.cityOptions = [];
      }
    },
    toPublish() {
      this.$router.push({
        path: "/cmsPublish"
      });
    },
    toIndex() {
      this.$router.push({
        path: "/cms/main/cmsIndex"
      });
    },
    tologin() {
      this.$router.push({
        path: "/cmsLogin"
      });
    },
    toAccount() {
      this.$router.push({
        path: "/cmsAcount"
      });
    },
    postAds() {
      this.outerVisible = true
    },
    toSearch() {
      this.$router.push({
        path: "/list?category=" + this.categoryName + "&city=" + this.cityName + "&query=" + this.queryName
      });
    },
    query(id) {
      let that = this
      getById(id).then(res => {
        console.log(res)
        that.form.createTime = res.data.createTime
        that.form.location = res.data.location
        that.form.views = res.data.views
        that.form.description = res.data.description
        that.form.phone = res.data.phone
        that.form.title = res.data.title
        that.form.id = res.data.id
        that.form.age = res.data.age
        that.form.city = res.data.city
        that.form.fullAddress = res.data.fullAddress
        that.form.type = res.data.category == 2 ? 'Bodyrubs' : 'Escorts'

        const options = {
          weekday: 'long',
          year: 'numeric',
          month: 'long',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit',
          hour12: true, // 使用12小时制
        };
        that.createTime = new Intl.DateTimeFormat('en-US', options).format(new Date(res.data.createTime))

        for (let i = 0; i < res.data.fileInfos.length; i++) {
          let currentFile = {name: '',url: ''};
          currentFile.name = res.data.fileInfos[i].fileObjectName;
          currentFile.url = that.url2 + res.data.fileInfos[i].filePath;
          that.fileListPut.push(currentFile);
        }
      })
    },
  },
  created() {
    this.getCityAndZhou()
    var id = this.$route.query.id
    if (id) {
      this.query(id)
    }
  },
  // p2 start
  computed: {
    ...mapGetters([
      'avatar',
      'name'
    ]),
    formattedDate() {
      console.log(this.form.createTime)
      const options = {
        weekday: 'long',
        year: 'numeric',
        month: 'long',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit',
        hour12: true, // 使用12小时制
      };
      return new Intl.DateTimeFormat('en-US', options).format(new Date("2022-03-31 00:00:01"));
    },
  },
  // p2 end
}
</script>

<style scoped>
/* 重置默认边距 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.page-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* 头部样式 */
.header {
  height: 60px;
  background-color: white;
  color: white;
  padding: 0 20px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.image_top {
  width: 252px;
  height: 52px;
  margin: 8px 0 0 240px;
}

.header-actions {
  display: flex;
  gap: 15px;
}

.my_btn {
  height: 40px;
  background: linear-gradient( #FF3A90 0%, #C6044B 100%);
  border-radius: 6px;
  font-family: SourceHanSansCN, SourceHanSansCN;
  font-weight: 500;
  font-size: 16px;
  color: #FFFFFF;
  line-height: 24px;
  text-align: center;
  font-style: normal;
  margin: 8px 0 0 calc(100vw - 1000px);
}

.login_btn {
  width: 84px;
}

.login_btn1 {
  width: 140px;
}

.postads_btn {
  width: 105px;
  height: 40px;
  background: #2D1B0B;
  border-radius: 6px;
  font-family: SourceHanSansCN, SourceHanSansCN;
  font-weight: 500;
  font-size: 16px;
  color: #FBD798;
  line-height: 24px;
  text-align: center;
  font-style: normal;
  margin: 8px 0 0 8px;
}

/* 中间内容区域 */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background-color: #FFF6F9;
}

.content {
  max-width: 1200px;
  margin: 0 auto;
}

.flex-row {
  display: flex;
  flex-direction: row;
}

.box_1 {
  max-width: 1200px;
  height: 52px;
  /*background: url(https://lanhu-oss-2537-2.lanhuapp.com/SketchPngf5d0297da7e4a7c3d534b43a2ea85fa403a16d5a578c427828027844f7782e13) 100% no-repeat;*/
  background: url(../cms/assets/img/search_bg.png) 100% no-repeat;
  background-size: 100% 100%;
  margin: 0 auto;
  justify-content: flex-start;
}

.search1 {
  /*width: 200px;*/
  width: calc(33vw - 40px);
  margin: auto 5px;
}

.search2 {
  width: 120px;
  /*width: 20%;*/
  height: 40px;
  text-align: center;
  margin: auto;
  color: #E81566;
  float: right;
}

.center_content {
  width: 60vw;
  margin: 0 auto;
  overflow-y: auto;
}

.steps {
  margin: 20px 0;
}

.step {
  width: 100%;
  /*height: calc(100vh - 195px);*/
  background-color: white;
  overflow-y:auto;
  padding-bottom: 200px;
  padding-top: 20px;
  padding-right: 20px;
}

.stepTitle {
  margin: 20px 0px 20px 32px;
  font-size: 24px;
  color: #111111;
}

.stepTitle2 {
  font-weight: 400;
  font-size: 16px;
  color: #666666;
}

.title {
  margin-top: 16px;
  height: 12px;
}

.title1 {
  margin-left: 20px;
  height: 30px;
  margin-top: 10px;
}

.title2 {
  background: #FFEFF5;
  width: 94%;
  margin: 0 auto;
  padding: 5px 10px;
  font-size: 20px;
  color: #111111;
  line-height: 40px;
  text-align: justify;
  font-style: normal;
}

.time2 {
  width: 94%;
  margin: 0 auto;
  font-weight: 400;
  font-size: 16px;
  color: #111111;
  line-height: 24px;
  text-align: left;
  font-style: normal;
  padding: 16px 0px;
}

.banner2 {
  width: 94%;
  margin: 0 auto;
  padding-bottom: 20px;
  background: #FFEFF5;
}

.split2 {
  width: 100%;
  height: 24px;
  background: #E81566;
  text-align: center;
  font-weight: 400;
  font-size: 12px;
  color: #FFFFFF;
  line-height: 24px;
}

.left {
  float: left;
  width: 100%;
}

table td {
  text-align: center;
}

tr:nth-child(even) {
  background: #FADDE8;
}

.container2 {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-top: 60px;
}

.title-text span {
  display: block;
  /*设置为块级元素会独占一行形成上下居中的效果*/
  position: relative;
  /*定位横线（当横线的父元素）*/
  /*居中文字的颜色*/
  text-align: center;
}

.title-text span:before, .title-text span:after {
  content: '';
  position: absolute;
  /*定位背景横线的位置*/
  top: 50%;
  background: #8c8c8c;
  /*背景横线颜色*/
  width: 35%;
  /*单侧横线的长度*/
  height: 1px;
}

.title-text span:before {
  left: 2%;
  /*调整背景横线的左右距离*/
}

.title-text span:after {
  right: 2%;
}

/deep/ .el-checkbox__label {
  white-space: normal;  /* 换行 */
  padding-right: 20px;
}

/deep/ .el-radio__label {
  padding-right: 20px;
}

/* 底部样式 */
.footer {
  height: 65px;
  background-color: #E81566;
  color: white;
  align-items: center;
  justify-content: center;
}

.footer1 {
  text-align: center;
  color: white;
  font-size: 14px;
  margin: 3px 0 0 0;
}

/* 相册样式 */
.photo-gallery {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.photo-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
  margin-top: 20px;
}

.photo-item {
  cursor: pointer;
  transition: transform 0.3s;
  overflow: hidden;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.photo-item:hover {
  transform: scale(1.03);
}

.thumbnail {
  width: 228px;
  height: 342px;
  object-fit: cover;
  display: block;
}

/* 模态框样式 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  cursor: zoom-out;
}

.modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  text-align: center;
}

.enlarged-photo {
  max-width: 100%;
  max-height: 85vh;
  display: block;
  margin: 0 auto;
}

.close {
  position: absolute;
  top: -40px;
  right: 0;
  color: white;
  font-size: 35px;
  font-weight: bold;
  cursor: pointer;
}

.photo-title {
  color: white;
  margin-top: 10px;
  font-size: 18px;
}

/* 导航按钮样式（可选） */
.nav-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.2);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}

.prev {
  left: 20px;
}

.next {
  right: 20px;
}

.box_2 {
  max-width: 1200px;
  height: 14px;
  font-size: 14px;
  margin: 10px 0px;
}

.thumbnail_2 {
  padding-right: 5px;
}
</style>
